package com.doitedu.day03.funcs

import scala.collection.immutable
import scala.collection.mutable.ListBuffer
import scala.io.Source

/**
 * @Date 22.6.22
 * @Created by HANGGE
 * @Description
 */
object _06FlattenMap方法 {
  def main(args: Array[String]): Unit = {

    val bs = Source.fromFile("E://words.txt")
    val lines = bs.getLines()
    val stringses: immutable.Seq[Array[String]] = lines.map(line => {
      val words = line.split("\\s+")
      words
    }).toList
    // 获取文件中所有的单词
    //val words: immutable.Seq[String] = stringses.flatten

    //  val numbers = List[Int](11,22,33,44,55)
    //  numbers.flatten

    /*   val  names = List[String] ("tom" , "rose" , "jim")

       val flatten: immutable.Seq[Char] = names.flatten*/

    /*   val ls = List[Array[String]](Array("java" , "java" ,"sql") ,
         Array("sql" , "sql" ,"hive") ,
         Array("hello" , "tom" ,"sql")
       )
       // 抽取集合中集合元素的元素
       val flat  = ls.flatten
       flat.foreach(println)*/

    // 统计每个单词出现的次数
    /*
      val ls = ListBuffer[String]()
    lines.map(line => {
         // 每行的所有单词
         val words = line.split("\\s+")
         words.foreach(word=>{
           ls.append(word)
         })
       })*/


    bs.close()


  }
}
